package com.smm.web.mtower.util;


import net.coobird.thumbnailator.Thumbnails;

import java.io.File;
import java.io.IOException;

/**
 * Created by zhenghao on 2016/6/13.
 *
 */
public class ImageUtil {


    /**
     * 压缩图片，不修改图片名称，删除原图
     * @param imageSavePath
     * @param imageName
     */
    public static void reduce(String imageSavePath,String imageName) throws IOException {

        // 0.8 倍压缩
        Thumbnails.of(imageSavePath+imageName).scale(0.7f).toFile(imageSavePath + "reduce_"+imageName);

        //压缩完成后，删除原图片
        File oldFile = new File(imageSavePath+imageName);

        oldFile.delete();

        //压缩图片重命名
        File newFile = new File(imageSavePath + "reduce_"+imageName);

        newFile.renameTo(oldFile);

    }


    public static void main(String[] args) throws Exception{

        ImageUtil.reduce("D:/images/","1465348716642.jpg");
    }
}
